<template>
  <div>
    <div>商品审核</div>
    <div>
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="输入关键词">
          <el-input
            v-model="searchForm.keyWord"
            placeholder="请输入商品名称"
            clearable
          />
        </el-form-item>
        <el-form-item label="选择状态">
          <el-select
            v-model="searchForm.statusId"
            placeholder="选择状态"
            style="width: 120px"
            clearable
          >
            <el-option label="草稿" :value="0" />
            <el-option label="待审核" :value="1" />
            <el-option label="已上线" :value="2" />
            <el-option label="已下线" :value="3" />
            <el-option label="缺货" :value="4" />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="loadList()">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="prodId" label="商品ID" width="50" />
        <el-table-column prop="prodSpu" label="SPU" width="50" />
        <el-table-column prop="prodName" label="商品名称" width="120">
          <template #default="scope">
            <span v-html="scope.row.prodName"></span>
          </template>
        </el-table-column>
        <el-table-column prop="kindName" label="商品种类" width="120" />
        <el-table-column prop="typeName" label="商品分类" width="120" />
        <el-table-column prop="brandName" label="品牌" width="80">
          <template #default="scope">
            <span v-html="scope.row.brandName"></span>
          </template>
        </el-table-column>
        <el-table-column prop="unitName" label="单位" width="50" />
        <el-table-column prop="tagName" label="标签" width="120" />
        <el-table-column prop="appr" label="供应商" width="120" />
        <el-table-column prop="prodImage" label="图片" width="120">
          <template #default="scope">
            <el-image
              :src="scope.row.prodImage"
              style="width: 50px; height: 50px"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="prodStatus" label="状态" width="120">
          <template #default="scope">
            <span v-if="scope.row.prodStatus == 0">草稿</span>
            <span v-if="scope.row.prodStatus == 1">待审核</span>
            <span v-if="scope.row.prodStatus == 2">已上线</span>
            <span v-if="scope.row.prodStatus == 3">已下线</span>
            <span v-if="scope.row.prodStatus == 4">已缺货</span>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="时间" width="120" />
        <el-table-column label="操作">
          <template #default="scope"></template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <div class="demo-pagination-block">
        <el-pagination
          v-model:current-page="searchForm.pageNum"
          v-model:page-size="searchForm.pageSize"
          :page-sizes="[2, 4, 6, 8]"
          :background="true"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ElMessage } from "element-plus";
import { getProdToEs } from "../api/api";
import { onMounted, reactive, ref } from "vue";

const searchForm = ref({
  keyWord: "",
  pageNum: 1,
  pageSize: 2,
  statusId: null,
});
const tableData = ref([]);
const total = ref(0);

//分页
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  loadList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  loadList();
};

//初始化数据
const loadList = () => {
  getProdToEs(searchForm.value).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};

onMounted(() => {
  loadList();
});
</script>

<style scoped></style>
